import { ESGltfModel } from 'earthsdk3';
import { ESUeViewer,UeESSceneObject } from 'earthsdk3-ue';
import { bind, track } from "earthsdk3";
import { ESRtsFeatureAdding } from '.';

export class UeESRtsFeatureAdding<T extends ESRtsFeatureAdding = ESRtsFeatureAdding> extends UeESSceneObject<T> {
    static readonly type = this.register<ESRtsFeatureAdding,ESUeViewer>("ESUeViewer", ESRtsFeatureAdding.type, this);
    static combinationClass = true;

    private _eSGltfModel = this.dv(new ESGltfModel());
    get eSGltfModel() { return this._eSGltfModel; }

    constructor(sceneObject: T, ueViewer: ESUeViewer) {
        super(sceneObject, ueViewer);

        const viewer = ueViewer.viewer;
        if (!viewer) {
            console.warn(`viewer is undefined!`);
            return;
        }

        //属性同步
        {
            const eSGltfModel = this.eSGltfModel;
            ueViewer.add(eSGltfModel);
            this.dispose(() => ueViewer.delete(eSGltfModel))

            this.d(track([eSGltfModel, 'url'], [sceneObject, 'url']));
            this.d(bind([eSGltfModel, 'editing'], [sceneObject, 'editing']));

            this.d(bind([eSGltfModel, 'position'], [sceneObject, 'position']));
            this.d(bind([eSGltfModel, 'rotation'], [sceneObject, 'rotation']));

        }

        //显隐控制
        {
            const updateShow = () => {
                this.eSGltfModel.show = sceneObject.show;
            }
            updateShow();
            this.d(sceneObject.showChanged.don(() => { updateShow() }));
        }
    }
}
